package com.pmcc.core.service;

import com.pmcc.core.entity.Answer;
import com.pmcc.core.entity.security.Employee;
import com.pmcc.core.repository.AnswerRepository;
import com.pmcc.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by spurs on 2018/11/15.
 */
@Service
@Transactional
public class AnswerService {
    @Autowired
    AnswerRepository answerRepository;

    /**
     * 密保问题设置
     */
    public ResultBean saveAnswer(Answer answer) {
        ResultBean resultBean = new ResultBean();
        resultBean.setResultCode(ResultBean.SUCCESS);
        try {
            Answer an = new Answer();
            an.setEmployeeId(answer.getEmployeeId());
            an.setAnswer(answer.getAnswer());
            an.setQuestionId(answer.getQuestionId());
            an.setUserName(answer.getUserName());
            answerRepository.saveAndFlush(an);
        } catch (Exception e) {
            resultBean.setResultCode(ResultBean.FAIL);
        }
        return resultBean;
    }
    /**
     * 查询验证是否设置密保问题
     *
     */
    public ResultBean queryAnswer(String employeeId) {
        ResultBean resultBean = new ResultBean();
        resultBean.setResultCode(ResultBean.SUCCESS);
        List<Answer> answerList = answerRepository.findByEmployeeId(employeeId);
        if(answerList.size()>0){
            resultBean.setRows(answerList);
        }
        return resultBean;
    }
}
